<!---
Name:        index.cfm
Author:      Dmitry Svito (prostotelo@gmail.com)
Description: catalog page
Created:     24.03.2011
--->

<cfparam name="Categ" type="integer" default="1">

<cfif IsDefined("URL.cat")>
	<cfset Categ = "#URL.cat#">
</cfif>

<!---Categories--->
<cfset CatObjGate = createObject("component", "Catalog.DataAccessLayer.CategoriesGateway").init() />
<cfset CatObjDAO = createObject("component", "Catalog.DataAccessLayer.CategoriesDAO").init() />
<cfset CategoriesAll = CatObjGate.getAll()>
<cfset CategoryRow = CatObjDAO.read(Categ)>

<!---Products--->
<cfset ProdObjGate	= createObject("component", "Catalog.DataAccessLayer.ProductsGateway").init() />
<cfset ProductsOfCat = ProdObjGate.getprodofcat(Categ)>

<!--- Include page header --->
<cfinclude template="/catalog/ViewLayer/header.cfm">

<head>
	<title>Joe's Catalog</title>
</head>

<table border=0 width=100% CELLPADDING="0" CELLSPACING="0" colspan=2>
	<tr>
		<td width="20%" valign="top" align="center">
			<h1>Categories</h1>
		<td width="60%" valign="top" align="center">
			<h1><cfoutput>#CategoryRow.getCategoryName()#</cfoutput> Products</h1>
	</tr>
	<tr>
		<td width="20%" valign="top" style="background-color:cyan">
			<ul>
				<cfif (ArrayLen(CategoriesAll) IS NOT 0)>
					<cfloop array="#CategoriesAll#" index="Name">
						<cfset CountOfCategory = ProdObjGate.countprodofcat(Name.getcategoryid())> 
		    			<cfoutput>
							<li>
								<a href = "index.cfm?cat=#Name.getCategoryId()#" target="_self">#Name.getCategoryname()#(#CountOfCategory#)<br></a>
							</li>								
						</cfoutput> 
					</cfloop>
				</cfif>
			</ul>
		</td>
		<td width="60%">
			<table width="100%" border="0" cellspacing="2" cellpadding="2">
				<tr>
				<cfif (ArrayLen(ProductsOfCat) IS NOT 0)>
					<cfset i = 1>
					<cfloop array="#ProductsOfCat#" index="PrOC">
					<cfoutput>					
						<cfif (i MOD 4) IS 0>
					        <td>
					        	#PrOC.getName()#<br>
			   					<a href = prodinfo.cfm?prod=#PrOC.getProductID()# target="_self">
			   						<cfif PrOC.getImageName() IS NOT "">
				   						<img src = "/catalog/images/#PrOC.getImageName()#" width="50" height="50" alt="">
									<cfelse>
				   						<img src = "/catalog/images/noimage.jpg" width="50" height="50" alt="">
									</cfif>
								</a><br>
								Price: #PrOC.getPrice()#<br>
								<cfset i = i + 1>
					        </td>
						</tr>
						<tr>
						<cfelse>
					        <td>
					        	#PrOC.getName()#<br>
			   					<a href = prodinfo.cfm?prod=#PrOC.getProductID()# target="_self">
			   						<cfif PrOC.getImageName() IS NOT "">
				   						<img src = "/catalog/images/#PrOC.getImageName()#" width="50" height="50" alt="">
									<cfelse>
				   						<img src = "/catalog/images/noimage.jpg" width="50" height="50" alt="">
									</cfif>
								</a><br>
								Price: #PrOC.getPrice()#<br>
								<cfset i = i + 1>
					        </td>				    					
						</cfif>
					</cfoutput>														
					</cfloop>
				</cfif>
				</tr>
			</table>
		</td>
	</tr>
</table>
<!---Message--->
<cfmessagebox buttontype="yesno" icon="question"
			labelyes="Confirm" labelno="Cancel"
			message="Are you sure?" modal="true"
			name="DelMes" title="Confirm deleting"
			type="confirm">
			
</cfmessagebox>

<script type="text/javascript">
	function ShowMes()
	{
		ColdFusion.MessageBox.show("DelMes");
	}
</script>

	<script type="text/javascript">
		ShowMes();
	</script>

<!--- Include page footer --->
<cfinclude template="/catalog/ViewLayer/footer.cfm">